package com.example.mvc.controller;

import com.example.mvc.bean.Book;
import com.example.mvc.bean.History;
import com.example.mvc.bean.User;
import com.example.mvc.service.BookBorrowService;
import com.example.mvc.service.BookService;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;

import java.io.IOException;
import java.util.List;
//查询图书日志页面按图书名称查询
@WebServlet("/queryBookBorrowHistoryListServlet")
public class QueryBookBorrowHistoryListServlet  extends HttpServlet {
    BookBorrowService bookBorrowService = new BookBorrowService();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String queryBookName = req.getParameter("queryBookName");
        List<History> bookHistoryStatusList = bookBorrowService.getQueryBookBorrowHistoryListByName(queryBookName);
        HttpSession session = req.getSession();
        session.setAttribute("bookHistoryStatusList", bookHistoryStatusList);
        User user = (User) session.getAttribute("user");
        int status = user.getStatus();
        String contextPath = req.getContextPath();
        if (status == 1) {
            resp.sendRedirect(contextPath + "/admin_index.jsp");
        } else {
            resp.sendRedirect(contextPath + "/admin_blog.jsp");
        }

    }

}

